#include <iostream>
#include <memory>
#include "Protocol.hpp"
namespace Calculator
{
    class Calculator
    {
    public:
        std::shared_ptr<Protocol::Response> Compute(std::shared_ptr<Protocol::Request> req)
        {
            int x = req->GetX();
            int y = req->GetY();
            char op = req->GetOper();

            Protocol::Factory fact;
            std::shared_ptr<Protocol::Response> resp = fact.BulidResponse();
            resp->GetCode() = Protocol::Success;

            switch (op)
            {
            case '+':
                resp->GetResult() = x + y;
                break;
            case '-':
                resp->GetResult() = x - y;
                break;
            case '*':
                resp->GetResult() = x * y;
                break;
            case '/':
            {
                if (y == 0)
                    resp->GetCode() = Protocol::Divide_Zero;
                else
                    resp->GetResult() = x / y;
                break;
            }
            case '%':
            {
                if (y == 0)
                    resp->GetCode() = Protocol::Modulo_Zero;
                else
                    resp->GetResult() = x % y;
                break;
            }

            default:
                resp->GetCode() = Protocol::Not_Recognized;
                break;
            }

            return resp;
        }
    };
}